//
//  UIButton+Extension.swift
//  LW_Weibo
//
//  Created by 刘伟 on 16/7/19.
//  Copyright © 2016年 LWSpro. All rights reserved.
//

import UIKit

extension UIButton {
    
    
    class func initButton(title: String?,titleFont: CGFloat,normalColor: UIColor,disabledColor: UIColor,normalImageName: String?,highlightedImageName: String?,disabledImageName: String?,target: AnyObject?, action: Selector,size: CGSize) -> UIButton {
        
        let button = UIButton()
        //  添加点击事件
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        //普通状态下  设置图片
        button.setBackgroundImage(UIImage(named: normalImageName ?? ""), forState: .Normal)
        //高亮状态下  设置图片
        button.setBackgroundImage(UIImage(named: highlightedImageName ?? ""), forState: .Highlighted)
        //禁用状态下  设置图片
        button.setBackgroundImage(UIImage(named: disabledImageName ?? ""), forState: .Disabled)
        
        //设置文字
        button.setTitle(title, forState: .Normal)
        //字体大小
        button.titleLabel?.font = UIFont.systemFontOfSize(titleFont)
        
        button.setTitleColor(normalColor, forState: .Normal)
        button.setTitleColor(disabledColor, forState: .Disabled)
        button.size = size
        //  因为button被UIBarButtonItem,这样设置没有作用
        //        button.enabled = false
        return button
   
        
        
    }
    
    
    
    
}
